
public class PerspectiveCamera {
	public Vector3 eye;
	public Vector3 front;
	public Vector3 refUp;
	public Vector3 up;
	public Vector3 right;
	public double fovScale;
	public double fov;
	
	public PerspectiveCamera(Vector3 eye, Vector3 front, Vector3 up, double fov)
	{
		this.eye = eye;
		this.front = front;
		this.refUp = up;
		this.fov = fov;
		
		init();
	}
	
	public void init()
	{
		right = front.cross(refUp);
		up = right.cross(front);
		fovScale = Math.tan(fov * 0.5 * Math.PI / 180) * 2;
	}
	
	public Ray3 generateRay(double x, double y)
	{
		Vector3 r = right.mul((x - 0.5) * fovScale);
		Vector3 u = up.mul((y - 0.5) * fovScale);
		
		return new Ray3(eye, front.add(r).add(u).normalize());
	}
}
